import tab from './tab'
import auth from './auth'
import cache from './cache'
import modal from './modal'
import download from './download'
//
import Api from '../api/index'
import DialogEdit from '../components/Dialog/edit.vue'
import DialogFile from '../components/Dialog/file.vue'
import DialogUploadImg from '../components/Dialog/uploadImg.vue'

export default {
  install(Vue) {
    // 挂载到body上,组件动作用handle控制
    function mount(com) {
      if (!com.$this) {
        com.$this = new (Vue.extend(com))();
        document.body.appendChild(com.$this.$mount().$el);
      }
      return com.$this;
    }

    // 页签操作
    Vue.prototype.$tab = tab
    // 认证对象
    Vue.prototype.$auth = auth
    // 缓存对象
    Vue.prototype.$cache = cache
    // 模态框对象
    Vue.prototype.$modal = modal
    // 下载文件
    Vue.prototype.$download = download
    // 文件上传
    Vue.prototype.$upload = (...arg) => mount(DialogFile).onUpload(...arg);
    // api
    Vue.prototype.api = Api;
    // 编辑弹框
    Vue.prototype.dialogEdit = (...arg) => mount(DialogEdit).onOpen(...arg);
    // 删除图片弹框
    Vue.prototype.dialogUploadImg = (...arg) => mount(DialogUploadImg).onOpen(...arg);
  }
}
